package com.bdqn.springbootmybatis.mapper;

//import com.bdqn.springbootmybatis.pojo.SysUser;
//import org.apache.ibatis.annotations.*;

import com.bdqn.springbootmybatis.pojo.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * SysUserMapper
 *
 * @author
 * @since 2021-11-25
 */
public interface SysUserMapper {

    @Insert("INSERT INTO sys_user(usr_name, usr_password, usr_role_id, usr_flag) VALUES (#{usrName}, #{usrPassword}, #{usrRoleId}, #{usrFlag})")
    <SysUser>
    void insert(SysUser user);

    @Delete("DELETE FROM sys_user WHERE usr_id = #{id}")
    void delete(Long id);

    @Update("<script>UPDATE sys_user <set> <if test=\"usrName != null\">usr_name=#{usrName},</if> <if test=\"usrPassword != null\">usr_password=#{usrPassword},</if> <if test=\"usrRoleId != null\">usr_role_id=#{usrRoleId},</if> <if test=\"usrFlag != null\">usr_flag=#{usrFlag},</if> </set> WHERE usr_id = #{usrId}</script>")
    void update(SysUser user);

    /**
     * 获取用户信息
     * @param id
     * @return
     */
    @Select("SELECT usr_id, usr_name, usr_password, usr_role_id, usr_flag FROM sys_user WHERE usr_id = #{id}")
    @Results({})
    SysUser get(Long id);

    /**
     * 获取所有用户信息
     *
     * @return
     */
    @Select("SELECT usr_id, usr_name, usr_password, usr_role_id, usr_flag FROM sys_user")
    @Results({})
    List<SysUser> findAll();
}
